// widget.h
#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QMap>
#include <QList>
#include <QUrl>
#include <QTimer>
#include <QMenu>

class DragFilter;

namespace Animation {
Q_NAMESPACE

enum ActionType {
    Dance,
    Punish,
    Run
};
Q_ENUM_NS(ActionType)

}

using namespace Animation;

class Widget : public QWidget
{
    Q_OBJECT
public:
    explicit Widget(QWidget *parent = nullptr);
    ~Widget();

    void playAnimation(ActionType type);

protected:
    void paintEvent(QPaintEvent* event) override;
    void contextMenuEvent(QContextMenuEvent* event) override;

private slots:
    void handleMenuAction(QAction* action);

private:
    void initResources();
    void setupMenu();

    QMap<ActionType, QList<QUrl>> m_animationFrames;
    QTimer* m_frameTimer;
    ActionType m_currentAction;
    QUrl m_currentFrame;
    QMenu* m_contextMenu;
};

class DragFilter : public QObject {
public:
    explicit DragFilter(QObject* parent = nullptr) : QObject(parent) {}
    bool eventFilter(QObject* obj, QEvent* event) override;

private:
    QPoint m_dragStartPos;
    bool m_dragging = false;
};

#endif // WIDGET_H
